package net.ib.mtalk.base;

import java.util.List;

import net.ib.mtalk.global.GlobalPreferences;
import net.ib.mtalk.network.NetFlowControl;
import net.ib.mtalk.service.SelecterService;
import net.ib.mtalk.util.LockActivity;
import android.app.ActivityManager;
import android.app.ExpandableListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.util.Log;
import android.widget.Toast;

public class BaseExpandableListActivity extends ExpandableListActivity 
{
	public void onDestroy()
	{
		super.onDestroy();
		new Handler().postDelayed(new Runnable(){
			public void run() 
			{
				ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
				List<ActivityManager.RunningTaskInfo> info = am.getRunningTasks(50);
				for(int i = 0 ; i < info.size() ; i++)
				{
					if(info.get(i).topActivity.getPackageName().equals(getPackageName()))
						return;
				}
				
				if(GlobalPreferences.getBooleanLockChk())
				{
					GlobalPreferences.setLock(true);
				}
				
				SelecterService.setMode(BaseExpandableListActivity.this, SelecterService.Mode.MONO_SELECT);
			}}, 300);
	}
	
	public void onResume()
	{
		super.onResume();
		if(GlobalPreferences.getLock())
		{
			Intent intent = new Intent(this, LockActivity.class);
			startActivity(intent);
		}
		
		NetFlowControl.tryGetAuth();
		SelecterService.setMode(BaseExpandableListActivity.this, SelecterService.Mode.FULL_SELECT);
	}
}
